package cn.jhg.account.tag;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

import cn.jhg.account.entity.User;

public class UserTag extends TagSupport {

	private User user;

	@Override
	public int doStartTag() throws JspException {
	
		try{
			JspWriter out = this.pageContext.getOut();
			if ( user == null ){
				out.println("no user");
				
				out.println("<h3>===========================</h3>");
				user = new User();
				user.setAccount("jhg");
				user.setStatus(999);
				user.setEmail("jhg@163.com");
//				return SKIP_BODY;
			}
            out.println("<table width='500px' border='1' align='center'>");

            out.println("<tr>");

            out.println("<td width='20%'>Username:</td>");

            out.println("<td>" + user.getAccount() + "</td>");

            out.println("</tr>");

            out.println("<tr>");

            out.println("<td>Age:</td>");

            out.println("<td>" + user.getStatus() + "</td>");

            out.println("</tr>");

            out.println("<tr>");

            out.println("<td>Email:</td>");

            out.println("<td>" + user.getEmail() + "</td>");

            out.println("</tr>");

            out.println("</table>");
		}
		catch(Exception e) {
            throw new JspException(e.getMessage());
        }

        return SKIP_BODY;
		
	}
	
    @Override
    public int doEndTag() throws JspException {

        return EVAL_PAGE;

    }
    
    @Override
    public void release() {

        super.release();

        this.user = null;

    }
    
    //getter and setters

    public User getUser() {

        return user;

    }

    public void setUser(User user) {

        this.user = user;

    }

}
